package com.meitutest.autoscript.fluency;

import android.os.Bundle;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiSelector;
import android.util.Log;

import org.junit.Before;
import org.junit.Test;

/**
 * Created by CrystalChen on 2017/9/2.
 */

public class LaunchTest {
    private UiDevice uiDevice;
    private SwipeDevice swipeDevice;
    private static String appName;

    public LaunchTest() {

    }

    @Before
    public void init() {
        uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        swipeDevice = new SwipeDevice(uiDevice);
        Bundle bundle = InstrumentationRegistry.getArguments();
        appName = bundle.getString("app_name");
        Log.e("cxq", "LaunchTest_init: "+appName);
    }


    @Test
    public void clickIconDir() throws Exception {
        uiDevice.pressHome();
        Thread.sleep(500);
        uiDevice.pressHome();
        Thread.sleep(500);
        uiDevice.pressHome();
        Thread.sleep(1000);
        UiObject app = uiDevice.findObject(new UiSelector().textContains(appName));
        while (!app.exists()) {
            swipeDevice.fromRight(1,100);
            Thread.sleep(1000);
            app = uiDevice.findObject(new UiSelector().textContains(appName));
        }
        app.click();

    }

}
